package com.pointi.emoEngine;

public class VoicedFrame
{
	public final int MaxFrame = 50 ;
	private int n_customer_default_subtime_range = 1;
	
	private int CurrentFrame  ;
	private int AngerCount ;
	private int NeutralCount ;
	private double [] Pitch ;
	private double [] Energy ;
	private double [][] MFCC ;

	public VoicedFrame()
	{
		//
	}

	public void InitVoicedFrame()
	{
		CurrentFrame = 0 ;
		AngerCount = 0 ;
		NeutralCount = 0 ;
		Pitch = new double [MaxFrame*n_customer_default_subtime_range] ;
		Energy = new double [MaxFrame*n_customer_default_subtime_range] ;
		MFCC = new double [MaxFrame*n_customer_default_subtime_range][12] ;
	}
	
	public void SetSubtimeRange(int n_sub_range)
	{
		n_customer_default_subtime_range = n_sub_range;
	}

	public void addVoicedFrame (double inPitch, double inEnergy, double [] inMFCC)
	{
		Pitch[CurrentFrame] = inPitch ;
		Energy[CurrentFrame] = inEnergy ;
		for (int i = 0 ; i < 12 ; i++) { MFCC[CurrentFrame][i] = inMFCC[i] ; }
		CurrentFrame ++ ;
	}

	public void setEnergy(double inEnergy, int n)
	{
		Energy[n] = inEnergy ;
	}

	public double [] getPitch ()
	{
		double [] outPitch = new double [CurrentFrame] ;
		System.arraycopy(Pitch, 0, outPitch, 0, CurrentFrame) ;
		return outPitch ;
	}

	public double [] getEnergy ()
	{
		double [] outEnergy = new double [CurrentFrame] ;
		System.arraycopy(Energy, 0, outEnergy, 0, CurrentFrame) ;
		return outEnergy ;
	}

	public double [][] getMFCC ()
	{
		double [][] outMFCC = new double [CurrentFrame][12] ;
		for (int i = 0 ; i < CurrentFrame ; i++)
		{
			System.arraycopy(MFCC[i], 0, outMFCC[i], 0, 12) ;
		}
		return outMFCC ;
	}

	public void setCount(int AngerCount, int NeutralCount)
	{
		this.AngerCount = AngerCount ;
		this.NeutralCount = NeutralCount ;
	}
	public int getAngerCount() { return AngerCount ;}
	public int getNeutralCount() { return NeutralCount ;}
	public int getCurrentFrame() { return CurrentFrame ; }
	public boolean isFull () { return (CurrentFrame == MaxFrame*n_customer_default_subtime_range) ? true : false ; }

	public void ClearVoicedFrame ()
	{
		for (int i = 0 ; i < CurrentFrame ; i++)
		{
			Pitch[i] = 0 ;
			Energy[i] = 0 ;
			for (int j = 0 ; j < 12 ; j++)
			{
				MFCC[i][j] = 0 ;
			}
		}
		CurrentFrame = 0 ;
	}
}
